package com.service.impl;

import com.domain.Function;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.FunctionMapper;
import com.service.FunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("FunctionService")
public class FunctionServiceImpl implements FunctionService {

    @Autowired
    private FunctionMapper functionMapper;

    @Override
    public PageInfo<Function> selectAll(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Function> functionList = functionMapper.selectAll();
        PageInfo<Function> pageInfo = new PageInfo<Function>(functionList);
        return pageInfo;
    }

    @Override
    public void delete(int id) {
        functionMapper.delete(id);
    }

    @Override
    public void insert(Function function) {
        functionMapper.insert(function);
    }

    @Override
    public void update(Function function) {
        functionMapper.update(function);
    }

    @Override
    public Function selectById(int id) {
        return functionMapper.selectById(id);
    }

    public PageInfo<Function> queryByOne(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Function> functionList = functionMapper.queryByOne();
        PageInfo<Function> pageInfo = new PageInfo<Function>(functionList);
        return pageInfo;
    }

    public PageInfo<Function> queryByZero(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Function> functionList = functionMapper.queryByZero();
        PageInfo<Function> pageInfo = new PageInfo<Function>(functionList);
        return pageInfo;
    }
}
